package com.example.qrcodecamera;

import android.content.Context;
import android.content.SharedPreferences;

public class SharedPreferencesHelper {
    private static final String PREFS_NAME = "db_config";
    private final SharedPreferences preferences;

    public SharedPreferencesHelper(Context context) {
        preferences = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
    }

    public void saveConfig(String ip, String port, String user, String password) {
        preferences.edit()
                .putString("ip", ip)
                .putString("port", port)
                .putString("username", user)
                .putString("password", password)
                .apply();
    }

    public String getIp() {
        return preferences.getString("ip", "");
    }

    public String getPort() {
        return preferences.getString("port", "3306");
    }

    public String getUsername() {
        return preferences.getString("username", "root");
    }

    public String getPassword() {
        return preferences.getString("password", "");
    }
}